package com.student.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.student.pojo.User;
import com.student.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author 是一个鸽子啊
 * @date 2020/4/14
 * @qq 364826415
 */
@RestController
public class UserAjaxController {
    @Autowired
    @Qualifier("userServiceImpl")
    private UserService userService;
    @RequestMapping("/checkUserName")
    private String checkUserName(String userName){
        User user = userService.queryUserByUserName(userName);
        String msg="";
        if (user !=null){
            msg="0";
        }else {
            msg="1";
        }
        return msg;

    }
    @RequestMapping("/queryUserByID")
    private String queryUserByID(String userID) throws JsonProcessingException {
        User user = userService.queryUserByID(Integer.parseInt(userID));
        ObjectMapper objectMapper = new ObjectMapper();
        String val = objectMapper.writeValueAsString(user);
        return val;
    }
}
